class ParkSelectList extends React.Component {
    constructor(props) {
        super(props);
        this.list = [];
    }

    componentDidUpdate() {
        if (this.props.defValue) {
            // noinspection JSPrimitiveTypeWrapperUsage
            this.refs.selectValue.value = this.props.defValue;
        }
        if (this.form) {
            this.form.render('select');
        }
    }

    onChange(data){
        this.selectCallback(data.value);
    }

    queryList(commCode) {
        let param = {};
        param.isNotPage = true;
        if (commCode){
            param.commCode = commCode;
        }
        postJson("/car/parkingLot/queryParkingLotList.x", param, function (data) {
            console.log(data)
            this.list = data.list;
            this.setState({
                selectValue: ''
            }, function () {
                this.selectCallback(this.refs.selectValue.value)
            }.bind(this));
        }.bind(this));
    }

    selectCallback(value) {
        if (this.props.selectCallback)
            this.props.selectCallback(value);
    }

    getDefValue() {
        return this.refs.selectValue.value;
    }

    optionView() {
        if (this.list.length > 0) {
            return this.list.map(function (array) {
                return (
                    <option
                        value={array.park_id}>{array.park_name}</option>
                );
            }.bind(this));
        } else {
            return (this.props.isDef ? '' : <option value="-1">请选择停车场</option>);
        }
    }

    render() {
        return <Select name="selectValue" ref="selectValue" onChange={(data) => this.onChange(data)}>
            {this.props.isDef ? <option value="-1">请选择停车场</option> : ''}
            {this.optionView()}
        </Select>
    }
}